package com.studyyoun.android.nonghe.home.activity;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.util.Log;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2015/8/28.
 */
public class Common {
    public static final String host = "http://m.mesage.cn";

    public static float face_ratio = 0.73f;     //相似度阀值 NDK R9 OPENCV 2.4
    public static float register_ratio = 0.60f;

    public static final String Dir_image = "Meou/cache/image";
    public static final String Dir_voice = "Meou/cache/voice";
    public static final String Dir_face = "Meou/cache/face";

    public static final String System = "Android";

    public static final String UserToMe = "_ToMe";
    public static final String MeToUser = "MeTo_";

    public static final int addFriend_MyCount = 15;   //发送15条消息成为好友
    public static final int addFriend_YouCount = 15;   //接收15条消息成为好友
    public static final int Harass = 5;  //接收5条就拉黑

    //扫脸相关
    public static final int Square_side = 200;  //取景正方形框的最终图片边长
    public static final int CompressImg_MaxKB = 150;    //文件最大size
    public static final float CompressImg_First = 0.8f;  //第一步压缩比例
    public static final float CompressImg_Step = 0.8f;  //循环压缩比例 (屏幕分辨率大的机型设置0.9会炸)

    //环信聊天服务器密码（帐号就是userid）
    public static final String password = "123456";

    //蓝牙使用
    public static String flags = "Meou_";

    public static final String rootDir = Environment.getExternalStorageDirectory() + "/Meou/";     // 存放文件的根目录

    public static final int ClipCountFor1s = 5;  // 1s截几帧

    public static final boolean IsPrintLog = true;    //是否打印LOG

    public static int ScreenWidth = 0;

    public static int ScreenHeight = 0;




    public static int getWidth(int imgWidthPx) {
        return ScreenWidth * imgWidthPx / 720;
    }

    public static int getHeight(int imgHeightPx) {
        return ScreenHeight * imgHeightPx / 1280;
    }

    //获取设备的唯一标识uuid

    //获取GUID
    public static String getGUID(){
        UUID GUID = UUID.randomUUID();
        return GUID.toString();
    }

    //md5加密操作
    public static String md5(String string) {
        byte[] hash;
        try {
            hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Huh, MD5 should be supported?", e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Huh, UTF-8 should be supported?", e);
        }

        StringBuilder hex = new StringBuilder(hash.length * 2);
        for (byte b : hash) {
            if ((b & 0xFF) < 0x10) hex.append("0");
            hex.append(Integer.toHexString(b & 0xFF));
        }
        return hex.toString();
    }

    /**
     * 获取格式化日期字符串
     *
     * @param mill
     * @return
     */
    public static String getDateFormatString(long mill) {
        Date date = new Date(mill);
        if (date == null)
            date = new Date();
        String formatStr = new String();
        SimpleDateFormat matter = new SimpleDateFormat("yyyyMMdd_HHmmss");
        formatStr = matter.format(date);
        return formatStr;
    }

    // 计算方位角pab。
    public static double gps2d(double lat_a, double lng_a, double lat_b, double lng_b){
        double d = 0;
        lat_a = lat_a * Math.PI / 180;
        lng_a = lng_a * Math.PI / 180;
        lat_b = lat_b * Math.PI / 180;
        lng_b = lng_b * Math.PI / 180;

        d = Math.sin(lat_a) * Math.sin(lat_b) + Math.cos(lat_a) * Math.cos(lat_b) * Math.cos(lng_b - lng_a);
        d = Math.sqrt(1 - d * d);
        d = Math.cos(lat_b) * Math.sin(lng_b - lng_a) / d;
        d = Math.asin(d) * 180 / Math.PI;

//     d = Math.round(d*10000);
        return d;
    }

}
